package cn.stylefeng.guns.modular.system.service;

import cn.stylefeng.guns.core.common.exception.BizExceptionEnum;
import cn.stylefeng.guns.modular.system.entity.SchoolCode;
import cn.stylefeng.guns.modular.system.entity.StudentCode;
import cn.stylefeng.guns.modular.system.mapper.StudentCodeMapper;
import cn.stylefeng.roses.core.util.ToolUtil;
import cn.stylefeng.roses.kernel.model.exception.ServiceException;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 考生号 服务类
 * </p>
 *
 * @author zfy
 * @since 2020-08-06
 */
@Service
public class StudentCodeService extends ServiceImpl<StudentCodeMapper,StudentCode> {
    public String getStudentCode (){
        StudentCode studentCode = this.getOne(new QueryWrapper<StudentCode>()
                .orderByAsc("code").last("limit 1"));
        if (ToolUtil.isEmpty(studentCode)){
            throw new ServiceException(BizExceptionEnum.DB_RESOURCE_NULL);
        }
        this.removeById(studentCode.getStudentCodeId());
        return String.format("%06d",studentCode.getCode());
    }

}
